@echo off
cls

SET buildtypeprefix=WINRT
SET clean=0
SET buildsuffix=32
SET buildtype=VC-%buildtypeprefix%%buildsuffix%
IF "%1"=="" GOTO DoBuild
IF /i "%1"=="help" GOTO ShowHelp
IF /i "%1"=="/?" GOTO ShowHelp
IF /i NOT "%1"=="clean" GOTO CheckSuffix
del ms\libeayrt.def
del ms\ssleayrt.def
SET clean=1
SHIFT
:CheckSuffix
IF NOT "%1"=="32" GOTO Check64
SET buildsuffix=32
SHIFT
GOTO Configure
:Check64 
IF NOT "%1"=="64" GOTO CheckARM
SET buildsuffix=64
SHIFT
GOTO Configure
:CheckARM
IF /i NOT "%1"=="ARM" GOTO Configure
SET buildsuffix=ARM
SHIFT
GOTO Configure
:CheckARM
IF /i NOT "%1"=="PHONE" GOTO Configure
SET buildsuffix=PHONE
SHIFT
:Configure
SET buildtype=VC-%buildtypeprefix%%buildsuffix%
@echo *****************************************************
@echo * Configure being run.                              *
@echo *****************************************************
perl Configure %buildtype% no-asm
SHIFT
@echo *****************************************************
@echo * Clean = %clean%                                   *
@echo *****************************************************
if %clean%==0 GOTO DoBuild
IF EXIST incrt del /Q /S incrt\*.*
IF EXIST outrt del /Q /S outrt\*.*
IF EXIST tmprt del /Q /S tmprt\*.*
IF EXIST out%buildtype% del /Q out%buildtype%\*.*
IF EXIST tmp%buildtype% del /Q tmp%buildtype%\*.*
IF EXIST inc%buildtype% del /Q inc%buildtype%\*.*
IF EXIST inc%buildtype% del /Q inc%buildtype%\openssl\*.*
IF EXIST tmp%buildtype%dll del /Q tmp%buildtype%dll\*.*
IF EXIST out%buildtype%dll del /Q out%buildtype%dll\*.*
IF EXIST tmp%buildtype%dll.dbg del /Q tmp%buildtype%dll.dbg\*.*
IF EXIST out%buildtype%dll.dbg del /Q out%buildtype%dll.dbg\*.*
:DoBuild
@echo *****************************************************
@echo * Build Type=%buildtype%                            * 
@echo *****************************************************
call ms\do_winrt.bat %buildtype% %buildsuffix%
nmake -f ms\nt.mak
GOTO AllDone
:ShowHelp
@echo ******************************************************************************************
@echo * Proper usage:                                                                          *
@echo *    "CleanAndBuild clean [32|64|ARM|PHONE]"                                                   *
@echo *                                                                                        *
@echo *  Make certain that the appropriate vcvars batch file has been run for the build type.  *
@echo ******************************************************************************************
:AllDone